home *** CD-ROM | disk | FTP | other *** search
Wrap
-- Net Get Text from URL -- behavior library version 1.1 -- This behavior can be used to as a general purpose getNetText script. -- The behavior is assigned to either a button or a frame Script. -- The required properties are: -- "On Which Event" - this is either MouseUp or ExitFrame. -- "URL" - this is an http path -- "Channel number of field" - this is the field that will receive the text. -- Use the Score channel number of the field. -- "Timeout seconds" - this is the amount of time in seconds that will pass -- before the getNetText call is aborted. -- IMPORTANT NOTE FOR USE IN A FRAME SCRIPT -- After this script is finished, the play head will progress -- to the next frame. Therefore, you will probably want to follow the -- frame that contains this script with a frame that contains the pResult -- field and a "go to the frame" script in the script channel. -- there are other options available. Use your imagination. -- You may use the URL http://www.cedub.com/bin/fortune.cgi as an example. -- This cgi script returns a line of text. property pNetID -- set to getLatestNetID() property pResult -- the spriteNum of field that receives netTextResult() property pStartAction -- if true, net operation is taking place property pExitFrameDone -- if true exitFrame operation if finished property pWhichEvent -- how the event is activated. mouseUp or exitFrame. property pURL -- which URL is called property pTicks -- number of ticks before the operation times out. property pEndTicks -- pTicks * 60. on mouseUp if pStartAction = FALSE then set pNetID = getNetText(pURL) -- this sets the netID and calls getNetText cursor 4 set pStartAction = TRUE -- the following sets up the timeout variable set pEndTicks = pTicks set pEndTicks = pEndTicks * 60 set pEndTicks = the ticks + pEndTicks end if end on prepareFrame me if pWhichEvent = #mouseUp then finishOperation end if end on exitFrame me if (pWhichEvent = #exitFrame) and (NOT pExitFrameDone = TRUE) then put pExitFrameDone if NOT pStartAction = TRUE then -- do the same work as on mouseUp set pNetID = getNetText(pURL) cursor 4 set pStartAction = TRUE set pEndTicks = pTicks set pEndTicks = pEndTicks * 60 set pEndTicks = the ticks + pEndTicks end if if pStartAction = TRUE then finishOperation go to the frame end if end if end on finishOperation me if (pStartAction = TRUE) and (the ticks > pEndTicks) then -- timeout has passed netAbort(pNetID) -- abort the operation set outputMember = the member of sprite pResult -- outputMember is a member ref set the text of outputMember = "Timeout!" set pStartAction = FALSE set pExitFrameDone = TRUE cursor 0 else if (pStartAction = TRUE) and (netDone(pNetID) = 1) then if NOT (netError(pNetID) = "") then -- netError has returned something if (netError() = "OK") or (netError() = "none") then -- complete the operation set outputMember = the member of sprite pResult set the text of outputMember = netTextResult(pNetID) set pStartAction = FALSE set pExitFrameDone = TRUE cursor 0 else -- operation failed set outputMember = the member of sprite pResult set the text of outputMember = netError() set pStartAction = FALSE set pExitFrameDone = TRUE cursor 0 end if end if end if end --- on beginSprite me set pStartAction = FALSE -- no action taking place yet end on getPropertyDescriptionList set p_list = [ #pURL: [ #comment: "Source URL:", #format: #string, #default: "http://www.cedub.com/bin/fortune.cgi" ], #pResult: [ #comment: "Target Sprite:", #format: #integer, #default: 1 ], #pWhichEvent: [ #comment: "Initializing Event:", #format: #symbol, #range: [ #MouseUp, #ExitFrame ], #default: #MouseUp ], #pTicks: [ #comment: "Network Timeout:", #format: #integer, #default: 40 ] ] return p_list end on getBehaviorDescription return "Loads text retrieved from the designated URL into a field castmember. Attach to sprites or frames." & RETURN & "PARAMETERS:" & RETURN & "ï Source URL - Enter the full URL of the desired text." & RETURN & "ï Target Sprite - Enter the channel number of a sprite with a field cast member in the current frame. The field cast member will hold the retrieved text." & RETURN & "ï Initializing Event - Specify the event that will trigger the behavior." & RETURN & "ï Network Timeout - Enter the number of seconds to wait before canceling operation due to no response from remote server." end -- 1/20/97 Chris Walcott